import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 *
 * @author javadb.com
 */
public class Main {
    
    /**
     * Example method for using the RandomAccessFile class
     */
    public void testRandomAccessFile(String filename) {
        
        RandomAccessFile randomAccessFile = null;
        try {
            
            //Declare variables that we're going to write
            String line1 = "First line\n";
            String line2 = "Second line\n";
            
            //Create RandomAccessFile instance with read / write permissions
            randomAccessFile = new RandomAccessFile("test", "rw");
            



            //Place the file pointer at the end of the first line
            randomAccessFile.seek(0);
            
            //Declare a buffer with the same length as the second line
            byte[] buffer = new byte[83];
            
            //Read data from the file
            randomAccessFile.read(buffer);
            
            //Print out the buffer contents
            System.out.println(new String(buffer));
            
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
          
                if (randomAccessFile != null)
                    randomAccessFile.close();
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main().testRandomAccessFile("myFile.txt");
    }
}